package com.string.builder;

import java.util.StringJoiner;

public class StringBuilder_test {
    public static void main(String[] args) {
        //用于拼接字符串 .append()
        //字符串反转
        //注意：！！！！！ 返回值为StringBuilder 获取字符需要toString()
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("abc");
        System.out.println(stringBuilder);
        stringBuilder.reverse();
        System.out.println(stringBuilder);
        System.out.println(stringBuilder.length());
        String s = stringBuilder.toString();
        System.out.println(s);

        //链式编程
        stringBuilder.append("abc").append("ccc").append("caa").reverse();
        System.out.println(stringBuilder);
        //更好的拼接方法 .add()
        StringJoiner sj = new StringJoiner("---", "[", "]");
        String str = "abc";
        String str1 = "abc1";
        String str2 = "abc2";
        sj.add(str).add(s).add(str2).add(str1);
        System.out.println(sj);

    }
}
